package com.bys.managercolok;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * 对话框（弹出框）
 */

public class SimpleDialog  extends Dialog {
    protected static int default_width = WindowManager.LayoutParams.WRAP_CONTENT;
    protected static int  default_height = WindowManager.LayoutParams.WRAP_CONTENT;
    protected Context context;
    private ImageView icon;
    private LinearLayout ll_button;
    private TextView dialog_title;
    private EditText dialog_message;
    public Button btn_confirm;
    private View.OnClickListener listener;
//    自定义视图
    private View customView;
    public SimpleDialog(@NonNull Context context,int style) {
        super(context,R.style.FullScreenDialog);
        this.context = context;
        customView = LayoutInflater.from(context).inflate(R.layout.dialog_simple,null);
        icon = customView.findViewById(R.id.icon);
        ll_button = customView.findViewById(R.id.ll_button);
        dialog_title = customView.findViewById(R.id.dialog_title);
        setTitle("显示信息：");
        dialog_message = customView.findViewById(R.id.dialog_message);
        dialog_message.clearFocus();
        btn_confirm = customView.findViewById(R.id.dialog_confirm);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(customView);


    }

    @Override
    public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK)
            return false;
        return super.onKeyDown(keyCode, event);
    }
    public SimpleDialog setMessage(String message){
        dialog_message.setText(message);
        return this;
    }
    public SimpleDialog setTitle(String title){
        dialog_title.setText(title);
        return this;
    }
    public SimpleDialog setIcon(int iconResId){
//        不可见，但这个View在ViewGroupt中不保留位置，
        dialog_title.setVisibility(View.GONE);
//        View.VISIBLE可见。
        icon.setVisibility(View.VISIBLE);
        icon.setBackgroundResource(iconResId);
        return this;

    }
    public SimpleDialog setClickListener(View.OnClickListener listener){
        this.listener = listener;
        btn_confirm.setOnClickListener(listener);
        return this;
    }

}
